package com.riekoff.particlecubeworld.editor.zonierung;

import java.util.ArrayList;
import java.util.List;

import cc.creativecomputing.CCApp;
import cc.creativecomputing.control.CCControl;
import cc.creativecomputing.graphics.texture.CCTexture.CCTextureFilter;
import cc.creativecomputing.graphics.texture.CCTexture.CCTextureTarget;
import cc.creativecomputing.graphics.texture.CCTexture.CCTextureWrap;
import cc.creativecomputing.graphics.texture.CCTexture2D;
import cc.creativecomputing.graphics.texture.CCTextureAttributes;
import cc.creativecomputing.graphics.texture.video.CCScreenCaptureData;
import cc.creativecomputing.graphics.texture.video.CCSequenceTexture;
import cc.creativecomputing.graphics.texture.video.CCVideoTexture;
import cc.creativecomputing.io.CCIOUtil;
import cc.creativecomputing.util.logging.CCLog;

public class AZonierungData {
	private CCScreenCaptureData _myData;
	private CCVideoTexture<CCScreenCaptureData> _myVideoTexture;
	
	@CCControl(name = "show border")
	private boolean _cShowBorder = false;
	
	private List<CCSequenceTexture>  _mySequences = new ArrayList<>();
	
	private List<String> _myMoviePaths = new ArrayList<>();

	public AZonierungData(CCApp theApp) {
		CCTextureAttributes myAttributes = new CCTextureAttributes();
		myAttributes.generateMipmaps(true);
		
		_myData = new CCScreenCaptureData(theApp, 100,100,100, 100, 20);
		
		_myVideoTexture = new CCVideoTexture<CCScreenCaptureData>(_myData, CCTextureTarget.TEXTURE_2D, myAttributes);
		_myVideoTexture.wrap(CCTextureWrap.REPEAT);
		CCLog.info("BLA");
		for(String myFolder : CCIOUtil.list("data/zonierungen") ){
			String[] myFiles = CCIOUtil.list("data/zonierungen/" + myFolder,"png");
			if(myFiles.length <= 0)continue;
			for(int i = 0; i < myFiles.length;i++) {
				myFiles[i] = "data/zonierungen/" + myFolder +"/" + myFiles[i];
			}
			
			CCTextureAttributes myAttributes2 = new CCTextureAttributes();
			myAttributes.generateMipmaps(false);
			
			CCSequenceTexture _mySequenceTexture = new CCSequenceTexture(null, CCTextureTarget.TEXTURE_2D, myAttributes2, myFiles);
			_mySequenceTexture.loop();
			_mySequenceTexture.textureFilter(CCTextureFilter.NEAREST);
			_mySequenceTexture.wrap(CCTextureWrap.REPEAT);
			_mySequenceTexture.frameRate(30);
			_mySequences.add(_mySequenceTexture);
			_myMoviePaths.add("data/zonierungen/" + myFolder);
		}
	}
	
	public String moviePath(int theIndex){
		if(theIndex >= _mySequences.size())return null;
		return _myMoviePaths.get(theIndex);
	}
	
	public CCSequenceTexture movie(int theIndex){
		if(theIndex >= _mySequences.size())return null;
		return _mySequences.get(theIndex);
	}
	
	public void update(final float theDeltaTime){
		_myData.grabArea().isActive(_cShowBorder);
	}
	
	public CCTexture2D grabTexture(){
		return _myVideoTexture;
	}
}
